package cn.lili.xiaoran.service.impl;

import cn.lili.xiaoran.entity.LiQuestionsDetail;
import cn.lili.xiaoran.mapper.LiQuestionsDetailMapper;
import cn.lili.xiaoran.service.LiQuestionsDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;

/**
 * 提问表(LiQuestionsDetail)表服务实现类
 *
 * @author makejava
 * @since 2022-08-14 13:52:41
 */
@Service("liQuestionsDetailService")
public class LiQuestionsDetailServiceImpl extends ServiceImpl<LiQuestionsDetailMapper, LiQuestionsDetail> implements LiQuestionsDetailService {
    @Resource
    private LiQuestionsDetailMapper liQuestionsDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public LiQuestionsDetail queryById(Integer id) {
        return this.liQuestionsDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param liQuestionsDetail 筛选条件
     * @param pageRequest       分页对象
     * @return 查询结果
     */
    @Override
    public Page<LiQuestionsDetail> queryByPage(LiQuestionsDetail liQuestionsDetail, PageRequest pageRequest) {
        long total = this.liQuestionsDetailDao.count(liQuestionsDetail);
        return new PageImpl<>(this.liQuestionsDetailDao.queryAllByLimit(liQuestionsDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param liQuestionsDetail 实例对象
     * @return 实例对象
     */
    @Override
    public LiQuestionsDetail insert(LiQuestionsDetail liQuestionsDetail) {
        this.liQuestionsDetailDao.insert(liQuestionsDetail);
        return liQuestionsDetail;
    }

    /**
     * 修改数据
     *
     * @param liQuestionsDetail 实例对象
     * @return 实例对象
     */
    @Override
    public LiQuestionsDetail update(LiQuestionsDetail liQuestionsDetail) {
        this.liQuestionsDetailDao.update(liQuestionsDetail);
        return this.queryById(liQuestionsDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.liQuestionsDetailDao.deleteById(id) > 0;
    }
}
